package com.hui.demo.quartz;

import com.hui.demo.model.User;
import com.hui.demo.mail.SendJunkMailService;
import com.hui.demo.service.UserService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 定时器类
 * @author ziv
 * @date 2018-12-19
 */
@Component
@Configurable
@EnableScheduling
public class SendMailQuartz {

    /**
     * 日志对象
     */
    private static final Logger logger = LogManager.getLogger(TestTask.class);

    @Resource
    private UserService userService;

    @Resource
    private SendJunkMailService sendJunkMailService;

    @Scheduled(cron = "*/5 * * * * *")
    public void run () {
        /*mpgmypepfvblfjfc*/
        List<User> userList = userService.findAll();
        if (userList != null && userList.size() > 0) {
            /**
             * 注释发送邮件方法
             */
            // sendJunkMailService.sendJunkMail(userList);
            logger.info("发送邮件！！！");
        }
        logger.info("邮件运行！！！");
    }
}
